<?php
    require ('./Config.php');
    header("Content-type: text/html; charset=utf-8");
    $Title_number = $_POST["Title_number"];
    $conn = new mysqli($MySqlHost,$MySqlUser,$MySqlPwd,$MySqlDatabaseName);
    mysqli_query($conn, "set character set 'utf8'");//读库
    mysqli_query($conn,"set names 'utf8'");//写库
    //$res = mysqli_query($conn,"SELECT * FROM other");
    $res = mysqli_query($conn,"SELECT COUNT(*) FROM other");
    $title_count = mysqli_fetch_row($res)[0]; //查询题目号
    mysqli_free_result($res); //释放内存
    $Random_title_number = array(); //随机题目号
    //产生不重复随机数
    $question_number_for_SQL = "";  //SQL查询用的题号
    for($array_len=0;$array_len<=$Title_number-1;$array_len++){  //产生数组
        $t = mt_rand(1,$title_count);  //产生随机数
        $p = 1;
        for($Determine_the =0;$Determine_the<=count($Random_title_number) - 1;$Determine_the++){    //判断重复
            if ($t == $Random_title_number[$Determine_the]){
                $p = 0;
            }
        }

        if ($p == 0){
            $array_len=$array_len-1;
        }else{
            $Random_title_number[$array_len] = $t;
            if ($array_len != $Title_number -1 ){
                $question_number_for_SQL =  $question_number_for_SQL."ID=". $Random_title_number[$array_len] . " OR "; //SQL查询用的题号
            }else{
                $question_number_for_SQL =  $question_number_for_SQL."ID=". $Random_title_number[$array_len];
            }
        }
    }

    //从数据库中抽题
    $res = mysqli_query($conn,"SELECT * FROM other WHERE ".$question_number_for_SQL);
    if(mysqli_num_rows($res) >= 0){
        $num = 0;
        for ($i=0;$i<=mysqli_num_rows($res) -1 ;$i++){
            $x = mysqli_fetch_row($res);
            $num++;
            echo "<div style='padding: 1%;margin:2% ;border:cornflowerblue solid;'>";
            echo "<h4>";
            echo $num.". ";
            echo $x[1]."</br></br>";
         //   echo $x[2]."</br>";
         //   echo $x[3]."</br>";
         //   echo $x[4]."</br>";
         //   echo $x[5]."</br>";
            for($j = 1;$j<=4;$j++){
                if($x[$j + 1 ]<>""){
                    if(chr($j+64)=="$x[6]"){
                        //<label for='Q/$num/$j'> 用来扩大单选按钮范围
                        //echo "<input type='radio' value='True' id='Q/$num/$j' name='$num' >".chr($j+64);//原有输出
                        //style='display: none;' 隐藏单选框
                        echo "<label for='Q/$num/$j'><div class='radio_style' onclick='BS(this.id)' id='Q/$num/$j.Fake'><input type='radio' value='True' id='Q/$num/$j' name='$num' style='display: none;' >".$x[$j+1]."</div></label><br/>";
                    }else{
                        //echo "<input type='radio' value='False' id='Q/$num/$j' name='$num'>".chr($j+64);//原有输出
                        echo "<label for='Q/$num/$j'><div class='radio_style' onclick='BS(this.id)' id='Q/$num/$j.Fake'><input type='radio' value='False' id='Q/$num/$j' name='$num' style='display: none;' >".$x[$j+1]."</div></label><br/>";
                    }
                }


            }
            echo "</h4>";
            echo "</div>";
        };
        echo "<center><div onclick='check()' class ='btn btn_giraffe' style='width:50%;text-align:center'>校对答案</div></cente>";
    }
    mysqli_free_result($res);//释放内存
    $conn ->close();


